package particlesystem.effects {
	import particlesystem.core.ParticleData;
	import particlesystem.utils.Range;

	/**
	 * @author robertthurston
	 */
	public class VelocityEffect implements IEffect {

		private var speed : Range;
		private var direction : Range;

		public function VelocityEffect(minSpeed : Number, maxSpeed : Number, startAngle : Number, endAngle : Number) {
			speed = new Range(minSpeed, maxSpeed);
			direction = new Range(startAngle * (Math.PI / 180), endAngle * (Math.PI / 180));
		}

		public function reset(particleData : ParticleData) : void {
			var newSpeed : Number = speed.range;
			
			particleData.direction = direction.range;
			
			particleData.xSpeed = newSpeed * Math.sin(particleData.direction);
			particleData.ySpeed = newSpeed * -Math.cos(particleData.direction);
		}

		public function update(particleData : ParticleData) : void {
			particleData.x += particleData.xSpeed;
			particleData.y += particleData.ySpeed;
		}
	}
}
